/*
 * alignStrings.h
 *
 *  Created on: 2011-09-16
 *      Author: pawel
 */

#ifndef ALIGNSTRINGS_H_
#define ALIGNSTRINGS_H_
#include"../smart2DArray.h"
#include<stdexcept>
struct cell;
struct optAlgParam;
struct optAlgThreadParam;

namespace btrack{
/*
 * Backtracking function uses object of this class to collect backtrack information
 */
class alignStrings{
private:
	/*
	 * smart2DArray objects are used as 1D C style strings
	 */
	smart2DArray<char> sQStr;
	smart2DArray<char> sDbStr;
	smart2DArray<char> sAlign;
	char *qStr;
	char *dbStr;
	char *aStr;
	/*
	 * length of string
	 */
	size_t length;
	/*
	 * actualposition
	 */
	size_t position;
	/*
	 * adress offset
	 */
	size_t off;
	bool stopSet;
	/*
	 * position of align in original sequences
	 */
	size_t queryAlignStart;
	size_t queryAlignStop;
	size_t dbAlignStart;
	size_t dbAlignStop;
	/*
	 * Identical letters
	 */
	size_t identity;
	/*
	 * similiar letters in alignment
	 */
	size_t similarity;
	/*
	 * Number of gaps in alignment
	 */
	size_t gaps;

public:
	/*
	 * Insert alignment characters
	 */
	int insert(const char& quer,const char& db,const char& direction);
	/*
	 * true if Stop positions in sequences are set
	 */
	int isStopSet()const;
	/*
	 * Set stop positions in sequences
	 * row col -position in direction matrix
	 */
	int setStop(const size_t &row,const size_t &col);
	/*
	 * Set start positions in sequences
	 * row col -position in direction matrix
	 */
	int setStart(const size_t &row,const size_t &col);
	/*
	 * return (number of identical letters)/length of alignment
	 */
	double getIdentity()const;
	/*
	 * return (number of similar letters)/length of alignment
	 */
	double getSimilarity()const;
	/*
	 * return (number of gaps)/length of alignment
	 */
	double getGaps()const;
	/*
	 * get trimmed strings from strings buffers
	 */
	char* getTrimmedQStr();
	char* getTrimmedDbStr();
	char* getTrimmedAStr();
	/*
	 * construct object with buffers of given length
	 */
	alignStrings(const size_t length)throw(std::logic_error);
	/*
	 * copy constructor
	 */
	alignStrings(const btrack::alignStrings& obj);
	/*
	 * Get alignment positions
	 */
	size_t getQueryAlignStart()const;
	size_t getQueryAlignStop()const;
	size_t getDbAlignStart()const;
	size_t getDbAlignStop()const;
	friend int btrack::backTrack(optAlgParam &param, const cell &traceCell,optAlgThreadParam &th);
};
}

#endif /* ALIGNSTRINGS_H_ */
